package cn.sxgan.gen.services.base;

import cn.sxgan.gen.enums.DataSourceType;
import cn.sxgan.gen.services.base.impl.MysqlQueryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 数据查询工厂
 * @Author: sxgan
 * @Date: 2025-07-16 17:45
 * @Version: 1.0
 **/
@Service
public class DataSourceQueryFactory {
    
    private final Map<String, DataSourceQuery> queryMap = new HashMap<>();
    
    @Autowired
    public DataSourceQueryFactory(MysqlQueryImpl mysqlQuery) {
        // 注册所有编辑器
        queryMap.put(DataSourceType.MySQL.getTypeName(), mysqlQuery);
    }
    
    public DataSourceQuery getDataSourceQuery(DataSourceType dataSourceType) {
        DataSourceQuery strategy = queryMap.get(dataSourceType.getTypeName());
        if (strategy == null) {
            throw new IllegalArgumentException("不支持的数据类型: " + dataSourceType);
        }
        return strategy;
    }
}
